package com.nc.delivery_project.client;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.nc.delivery_project.client.add_department.AddDepartmentActivity;
import com.nc.delivery_project.client.add_department.AddDepartmentPlace;
import com.nc.delivery_project.client.add_schedule.AddScheduleActivity;
import com.nc.delivery_project.client.add_schedule.AddSchedulePlace;
import com.nc.delivery_project.client.add_user.AddUserActivity;
import com.nc.delivery_project.client.add_user.AddUserPlace;
import com.nc.delivery_project.client.department_details.DepartmentDetailsActivity;
import com.nc.delivery_project.client.department_details.DepartmentDetailsPlace;
import com.nc.delivery_project.client.departments.DepartmentsActivity;
import com.nc.delivery_project.client.departments.DepartmentsPlace;
import com.nc.delivery_project.client.cargo_details.CargoDetailsActivity;
import com.nc.delivery_project.client.cargo_details.CargoDetailsPlace;
import com.nc.delivery_project.client.order_details.OrderDetailsActivity;
import com.nc.delivery_project.client.order_details.OrderDetailsPlace;
import com.nc.delivery_project.client.orders.OrdersActivity;
import com.nc.delivery_project.client.orders.OrdersPlace;
import com.nc.delivery_project.client.schedules.SchedulesActivity;
import com.nc.delivery_project.client.schedules.SchedulesPlace;
import com.nc.delivery_project.client.user_details.UserDetailsActivity;
import com.nc.delivery_project.client.user_details.UserDetailsPlace;
import com.nc.delivery_project.client.schedule_details.ScheduleDetailsActivity;
import com.nc.delivery_project.client.schedule_details.ScheduleDetailsPlace;
import com.nc.delivery_project.client.statistics.StatisticsActivity;
import com.nc.delivery_project.client.statistics.StatisticsPlace;
import com.nc.delivery_project.client.users.UsersActivity;
import com.nc.delivery_project.client.users.UsersPlace;

/**
 * Created by miroshnik on 12/28/2014.
 */
public class AppActivityMapper implements ActivityMapper {

    private ClientFactory clientFactory;

    /**
     * AppActivityMapper associates each Place with its corresponding
     * {@link Activity}
     *
     * @param clientFactory Factory to be passed to activities
     */
    public AppActivityMapper(ClientFactory clientFactory) {
        super();
        this.clientFactory = clientFactory;
    }

    /**
     * Map each Place to its corresponding Activity.
     */
    @Override
    public Activity getActivity(Place place) {
        Activity activity = null;

        if (place instanceof UsersPlace) {
            activity = new UsersActivity((UsersPlace) place, clientFactory);
        } else if (place instanceof UserDetailsPlace) {
            activity = new UserDetailsActivity((UserDetailsPlace) place, clientFactory);
        } else if (place instanceof ScheduleDetailsPlace) {
            activity = new ScheduleDetailsActivity((ScheduleDetailsPlace) place, clientFactory);
        } else if (place instanceof AddSchedulePlace) {
            activity = new AddScheduleActivity((AddSchedulePlace) place, clientFactory);
        } else if (place instanceof AddUserPlace) {
            activity = new AddUserActivity((AddUserPlace) place, clientFactory);
        } else if (place instanceof OrdersPlace)
        {
            activity = new OrdersActivity((OrdersPlace)place, clientFactory);
        } else if (place instanceof DepartmentsPlace) {
        	activity = new DepartmentsActivity((DepartmentsPlace)place, clientFactory);
		}else if (place instanceof AddDepartmentPlace) {
            activity = new AddDepartmentActivity((AddDepartmentPlace) place, clientFactory);
		}else if (place instanceof DepartmentDetailsPlace) {
            activity = new DepartmentDetailsActivity((DepartmentDetailsPlace) place, clientFactory);
		} else if (place instanceof SchedulesPlace) {
            activity = new SchedulesActivity((SchedulesPlace) place, clientFactory);
        }
        else if (place instanceof OrderDetailsPlace)
        {
            activity = new OrderDetailsActivity((OrderDetailsPlace) place, clientFactory);
        }
        else if (place instanceof CargoDetailsPlace)
        {
            activity = new CargoDetailsActivity((CargoDetailsPlace)place,clientFactory);
        }
        else if (place instanceof StatisticsPlace)
        {
            activity = new StatisticsActivity((StatisticsPlace)place,clientFactory);
        }
        //clientFactory.track();

        return activity;
    }

}
